from django.db import models

# Create your models here.
from django.contrib.auth.models import AbstractUser, Group
from datetime import datetime

class UserProfile(AbstractUser):
    mobile = models.CharField(max_length=11, null=True, blank=True, verbose_name='手机号')
    email = models.CharField(max_length=100, null=True, blank=True, verbose_name='邮箱')
    site = models.CharField(max_length=100, null=True, blank=True, verbose_name='公司网址')
    company_name = models.CharField(max_length=100, null=True, blank=True, verbose_name='公司名称')
    principal = models.CharField(max_length=20, null=True, blank=True, verbose_name='负责人')
    groups = models.ManyToManyField(Group, blank=True, verbose_name='角色')
    vip = models.IntegerField(default=0, choices=((0, '非会员'), (1, '99会员')), verbose_name='会员状态')
    pay_times = models.IntegerField(default=0, null=True, blank=True, verbose_name='充值次数')
    start_time = models.DateTimeField(default=datetime.now(), null=True, blank=True, verbose_name='购买时间')
    renewal_time = models.DateTimeField(default=datetime.now(), null=True, blank=True, verbose_name='续期时间')
    finish_time = models.DateTimeField(default=datetime.now(), null=True, blank=True, verbose_name='到期时间')

    class Meta:
        verbose_name = "用户"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username

    def group_list(self):
        return ','.join([i.Name for i in self.groups.all()])


class VerifyCode(models.Model):
    """
    短信验证码
    """
    code = models.CharField(max_length=10, verbose_name="验证码")
    mobile = models.CharField(max_length=11, verbose_name="电话")
    add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = "短信验证码"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.code
